import { ElMessageBox, ElMessage } from 'element-plus';

export const $alert = (s) => { ElMessageBox.alert(s) };
export const $success = (s) => { ElMessage.success(s) };
export const $error = (s) => { ElMessage.error(s) };
export function $confirm(message) {
  return new Promise(resolve => {
    ElMessageBox.confirm(message).then(() => {
      resolve(true);
    }).catch(() => {
      resolve();
    });
  });
}
export function $prompt(message, { value = '', placeholder, isTextarea } = {}) {
  return new Promise(resolve => {
    ElMessageBox.prompt(`请输入${message}`, '确认', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      inputPattern: /[^\s]+/,
      inputValue: value,
      inputPlaceholder: placeholder,
      inputType: isTextarea ? 'textarea' : 'input',
      inputErrorMessage: `${message}不能为空`
    }).then(({ value }) => {
      resolve(value);
    }).catch(() => {
      resolve();
    });
  });
}

